package util.http;

import org.apache.http.HttpEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.nio.charset.Charset;

/**
 * @Desciption: copy from dajia StringResponseHandler
 * @author: Anc
 * @date: 2022/7/01
 */
public class StringResponseHandler extends BasicResponseHandler {
    private Charset charset;

    public StringResponseHandler(Charset charset) {
        this.charset = charset;
    }

    public StringResponseHandler() {
        this.charset = Charset.forName("UTF-8");
    }

    @Override
    public String handleEntity(HttpEntity entity) throws IOException {
        return EntityUtils.toString(entity, this.charset);
    }
}
